﻿var currPrintMedia;
var currPrintMethod;
var quantity = 100;

$(document).ready(function() {
    $('a[title="paper"]').each(function() {
        $(this).click(function() {
            onItemClick($(this), 'paper');
            recalculatePrice();
        });
    });

    $('a[title="colors"]').each(function() {
        $(this).click(function() {
            onItemClick($(this), 'colors');
            recalculatePrice();
        });
    });

    $('a[title="side"]').each(function() {
        $(this).click(function() {
            onToggleLinkClick($(this), 'side');
        });
    });

    $('a[title="paper-type"]').each(function() {
        $(this).click(function() {
            onToggleLinkClick($(this), 'paper-type');
        });
    });

});


function recalculatePrice() {
    //Todo ADD loading animation anywhere
    $.getJSON("/en/Price/" + quantity + "/" + currPrintMedia + "/" + currPrintMethod,
            function(data) {
                $('label#price-label').html(data.Price);
    });
}

function onItemClick(papObj, title) {
    $('a[title="'+ title+'"].select-item-selected:first').removeClass("select-item-selected");
    papObj.addClass("select-item-selected");

    if (title == 'colors') {
        currPrintMethod = papObj.attr('id');
        $('p#print-method-desc').html(papObj.find('div.invisible').html());
        $('label#print-method-label').html(papObj.find('label').html());
        $('#print-method-hidden').val(currPrintMethod);
    }
    if (title == 'paper') {
        currPrintMedia = papObj.attr('id');
        $('p#print-media-desc').html(papObj.find('div.invisible').html());
        $('label#print-media-label').html(papObj.find('label').html());
        $('#print-media-hidden').val(currPrintMedia);
    }
}


function onToggleLinkClick(toggleObj, title) {
    $('a[title="' + title + '"].toggle-link-selected:first').removeClass("toggle-link-selected");
    toggleObj.addClass("toggle-link-selected");
}


